<?php

/*

Mail Delete (mail_delete.pro.php)

*/
ob_start();
include "global.inc.php";

if ($id)
{
	$check = fetch("SELECT id FROM mail_topics2 WHERE id = '$id' AND to_user = '$userid' AND game = '$game'");

	if (!$check[id])
	{
		die(header(error("mail.php?game=$game","That mail does not exist.")));
	}
	else
	{
		mysql_query("DELETE FROM mail_topics2 WHERE id = '$id' AND to_user = '$userid' AND game = '$game'");
		mysql_query("DELETE FROM mail_messages2 WHERE mail_id = '$id' AND game = '$game'");
		die(header(error("mail.php?game=$game","The mail has been deleted.")));
	}
}

if ($all == "true")
{
	mysql_query("DELETE FROM mail_topics2 WHERE to_user = '$userid' AND id <= '$lastid' AND game = '$game'");
	mysql_query("DELETE FROM mail_messages2 WHERE to_user = '$userid' AND mail_id <= '$lastid' AND game = '$game'");
	die(header(error("mail.php?game=$game","Your inbox has been cleared.")));
}

if ($deleteall == "Delete Checked")
{
	$findMail = mysql_query("SELECT * FROM mail_topics2 WHERE to_user = '$userid' AND game = '$game'");
	while($getMail = mysql_fetch_array($findMail))
	{
		$mailID = $getMail[id];
		if ($mailAction[$mailID] == 1)
		{
			mysql_query("DELETE FROM mail_topics2 WHERE to_user = '$userid' AND id = '$mailID' AND game = '$game'");
		}
	}
	die(header(error("mail.php?game=$game","The selected mails have been deleted.")));
}

?>